<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Denoising GAN</title>

    <!-- Bootstrap Core CSS -->
    <link href="{{url_for('static', filename='css/bootstrap.min.css')}}" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="{{url_for('static', filename='css/4-col-portfolio.css')}}" rel="stylesheet">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body>

    <!-- Navigation -->
    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
        <div class="container">
            <!-- Brand and toggle get grouped for better mobile display -->
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="#">CS523Project3</a>
            </div>
            <!-- Collect the nav links, forms, and other content for toggling -->

            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container -->
    </nav>

    <!-- Page Content -->
    <div class="container">

        <!-- Page Heading -->
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">Denoising GAN

                </h1>
            </div>
        </div>
        <!-- /.row -->

        <!-- Projects Row -->
        <div class="row">
            <div class="col-md-4">
                <h2>Input</h2>
            
                    <img id="inputImg" class="img-responsive" src="http://placehold.it/256x144" alt="">
                
                <form id="imgUpload" enctype="multipart/form-data">
             
                <input name="file" type="file" id="imgInp" />
                </form>

            </div>
            
            <div class="col-md-4">
                <h2>Output</h2>
              
                    <img id='outputImg' class="img-responsive" src="http://placehold.it/256x144" alt="">
    
            </div>
        </div>
        <div class="row">
          <div class="col-md-2 col-md-offset-3" style="">
                
                <button id="denoiseButton" type="button" class="btn btn-primary btn-lg">Denoise</button>
                
            </div>
        </div>
        <!-- /.row -->


        <!-- /.row -->

        <hr>



        <hr>

        <!-- Footer -->
        <footer>
            <div class="row">
                <div class="col-lg-12">

                </div>
            </div>
            <!-- /.row -->
        </footer>

    </div>
    <!-- /.container -->

    <!-- jQuery -->
    <script src={{url_for('static', filename="js/jquery.js")}}></script>

    <!-- Bootstrap Core JavaScript -->
    <script src={{url_for('static', filename="js/bootstrap.min.js")}}></script>

    <script>
    $( document ).ready(function() {
      function readURL(input) {
          if (input.files && input.files[0]) {
              var reader = new FileReader();

              reader.onload = function (e) {
                  $('#inputImg').attr('src', e.target.result);
              }

              reader.readAsDataURL(input.files[0]);
          }
      }

      $("#imgInp").change(function(){
          readURL(this);
      });


       $('#denoiseButton').bind('click', function() {


         $.ajax({
             url: "/denoisify",
             type: "POST",
             data: new FormData($('#imgUpload')[0]),
             cache: false,
             contentType: false,
             processData: false,
             async:false,
             dataType: 'json',
             success: function (result) {
              console.log(result);
              d = new Date();
                 $('#outputImg').attr('src', '/static/output.png?'+d.getTime())
             },

         });
       });
     });

    </script>

</body>

</html>
